var headers = {
	token: "Jwt-Token",
	sign: "Jwt-Sign",
	secret: "Jwt-Secret",
	millis: "Jwt-Millis",
	nonce: "Jwt-Nonce",
	code: "Jwt-Code",
	date: "Jwt-Date",
};

function getDispLen(num) {
	var len = 0;
	if (num == 1) {
		len = 400;
	} else if (num == 2) {
		len = 1200;
	} else if (num == 3) {
		len = 3600;
	} else if (num == 4) {
		len = 10800;
	} else if (num == 5) {
		len = 25600;
	}
	return len;
}

function getDispData(num, key) {
	var len = getDispLen(num);
	var str = localStorage.getItem(key);
	var resp = JSON.parse(str);
	var unit = resp.unit;
	var xData_all = resp.xData;
	var yData1_all = resp.yData1;
	var xData = [];
	var yData1 = [];
	for (var i = 0; i < len; i++) {
		xData.push(xData_all[i]);
		yData1.push(yData1_all[i]);
	}
	return {
		xData: xData,
		yData1: yData1,
		unit: unit
	};
}

function getDispDataByLen(len, key) {
	var str = localStorage.getItem(key);
	var resp = JSON.parse(str);
	var unit = resp.unit;
	var xData_all = resp.xData;
	var yData1_all = resp.yData1;
	var xData = [];
	var yData1 = [];

	if (xData_all == null || xData_all == undefined || xData_all == "undefined" || xData_all == NaN || xData_all.length ==
		0) {

	} else {

		for (var i = 0; i < len; i++) {
			xData.push(xData_all[i]);
			yData1.push(yData1_all[i]);
		}

	}

	return {
		xData: xData,
		yData1: yData1,
		unit: unit
	};
}


function getDispData_pubu(num, key) {
	var len = getDispLen(num);
	var str = localStorage.getItem(key);
	var resp = JSON.parse(str);
	var unit = resp.unit;
	var xData_all = resp.xData;
	//优化 a_yData1
	var yData1_all = resp.a_yData1;
	var xData = [];
	var yData1 = [];
	for (var i = 0; i < len; i++) {
		xData.push(xData_all[i]);
		yData1.push(yData1_all[i]);
	}
	return {
		xData: xData,
		yData1: yData1,
		unit: unit
	};
}

function getObjStr(str) {
	if (str == "" || str == null || str == undefined || str == NaN) {
		return "";
	} else {
		return str;
	}
}

function getUrlParam(key) {
	var href = window.location.href;
	var url = href.split("?");
	if (url.length <= 1) {
		return "";
	}
	var params = url[1].split("&");
	for (var i = 0; i < params.length; i++) {
		var param = params[i].split("=");
		if (key == param[0]) {
			return param[1];
		}
	}
}

function doSetToken() {
	var token = getUrlParam("token");
	localStorage.setItem("token", token);
}

doSetToken();

function doTabStyleAction(label) {

	$(".tab-span").removeClass("tabs-item-text-active");
	$(".tab-item").removeClass("tabs-item-bar-active");

	$(".tab-span[data-label='" + label + "']").addClass("tabs-item-text-active");
	$(".tab-item[data-label='" + label + "']").addClass("tabs-item-bar-active");

}

function doGetTabStr(resp) {

	var tab_str = "";

	$(resp.list).each(function(i, v) {
		// var str = "";
		tab_str += '<div class="swiper-slide" style="display: inline-block;" onclick="doTabSelEvent(' + v.label + ')">';
		//tab_str += '<div class="swiper-slide tab-clk" style="display: inline-block;" data-label="' + v.label + '">';
		if (i == 0) {
			tab_str += '<span class="tabs-item-text tabs-item-text-active tab-span" data-label="' + v.label + '">' + v.label +
				'</span>';
			tab_str += '<div class="tabs-item-bar tabs-item-bar-active tab-item" data-label="' + v.label + '"></div>';
		} else {
			tab_str += '<span class="tabs-item-text tab-span" data-label="' + v.label + '">' + v.label + '</span>';
			tab_str += '<div class="tabs-item-bar tab-item" data-label="' + v.label + '"></div>';
		}
		tab_str += '</div>';
	});

	return tab_str;

}

function doSwiperInit(cont, page) {

	var swiper = new Swiper(cont, {
		slidesPerView: 1,
		spaceBetween: 10,
		// init: false,
		pagination: {
			el: page,
			clickable: true,
		},
		breakpoints: {
			'@0.00': {
				slidesPerView: 5,
				spaceBetween: 0,
			},
			'@0.75': {
				slidesPerView: 6,
				spaceBetween: 0,
			},
			'@1.00': {
				slidesPerView: 7,
				spaceBetween: 0,
			},
			'@1.50': {
				slidesPerView: 8,
				spaceBetween: 0,
			},
			'@2.00': {
				slidesPerView: 9,
				spaceBetween: 0,
			},
			'@2.50': {
				slidesPerView: 10,
				spaceBetween: 0,
			},
			'@3.00': {
				slidesPerView: 11,
				spaceBetween: 0,
			},
			'@3.50': {
				slidesPerView: 12,
				spaceBetween: 0,
			},
		}
	});

}

function doGetHeaders() {
	var version = "1.0";
	var token = localStorage.getItem('token');
	var token_json = getTokenJson(token);
	//getSignJson(secret, code, version)
	var myDate = new Date();
	var millis = parseInt(myDate.getTime() / 1000);
	var sign_json = getSignJson(token_json.secret, token_json.code, version, millis);
	return { // 默认添加请求头
		"Jwt-Token": token_json.token,
		"Jwt-Sign": sign_json.sign,
		"Jwt-Secret": sign_json.secret,
		"Jwt-Millis": sign_json.millis,
		"Jwt-Nonce": sign_json.nonce,
		"Jwt-Code": token_json.code,
		"Jwt-Date": sign_json.date,
	}
}

function getUrlArgs(url) {
	
	var url_pre2 = "http://192.168.3.254:8085/smkj/wave/";
	var url_pre = "http://smheee.com:8085/smkj/wave/";

	var data = {}
	data.time = ''
	data.meas_def = '加速度'
	data.box_no = '2'
	data.box_io_no = '2'

	return {
		url: url_pre + url,
		method: 'get',
		data: data,
		headers: doGetHeaders()
	};
	
}
